package com.alangyun.remind.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.alangyun.remind.error.MindException;
import com.alangyun.remind.repository.data.EmployeeCaution;
import com.alangyun.remind.service.IEmployeeService;
import com.alangyun.remind.service.IUploadService;
import com.alangyun.remind.vo.DataResponse;
import com.alangyun.remind.vo.ErrorCode;
import com.alangyun.remind.vo.FilterParam;
import com.alangyun.remind.vo.Response;
import com.alangyun.remind.vo.user.JobView;
import com.alangyun.remind.vo.user.SpecialView;
import com.alangyun.remind.vo.user.UserView;
import java.util.List;


/**
 * 员工管理模块
 *
 * @class com.alangyun.remind.controller.EmployeeController
 * @company 北京诚朗信息技术有限公司
 * @author hoobort klxukun@126.com
 * @datetime 2022年11月10日 下午1:33:09
 *
 */
@Controller
public class EmployeeController extends AbstractController {
	@Resource
	private IUploadService svcUpload;
	@Resource
	private IEmployeeService svcData;

	@PostMapping(value = Paths.EmployeeUrl.EMP_UPLOAD)
	@ResponseBody
	public Response talentUpload(@RequestParam("file") MultipartFile file) {
		Response ret = new Response();
		try {
			validateTimeout();
			
			svcUpload.parseEmployeeFile(file);
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("上传人才开发数据预警数据处理失败");
			e("上传人才开发数据预警数据处理失败", ex);
		}
		return ret;
	}

	@PostMapping(value = Paths.EmployeeUrl.EMP_NAV_TREE)
	@ResponseBody
	public DataResponse<FilterParam> categories() {
		DataResponse<FilterParam> ret = new DataResponse<FilterParam>();
		try {
			validateTimeout();
			
			ret.setData(svcData.categroies());
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("提取过滤参数失败");
			e("提取过滤参数失败", ex);
		}

		return ret;
	}


	@PostMapping(value = Paths.EmployeeUrl.EMP_SPECIAL_UPDATE)
	@ResponseBody
	public DataResponse<EmployeeCaution> updateSpecialUserModel(@RequestBody EmployeeCaution data) {
		DataResponse<EmployeeCaution> ret = new DataResponse<EmployeeCaution>();
		try {
			validateTimeout();

			ret.setData(svcData.updateSpecialUser(data));
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("更新特殊岗位适配模型失败");
			e("更新特殊岗位适配模型失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.EmployeeUrl.EMP_SPECIAL_FIND)
	@ResponseBody
	public DataResponse<EmployeeCaution> findSpecialUserModel() {
		DataResponse<EmployeeCaution> ret = new DataResponse<EmployeeCaution>();
		try {
			validateTimeout();
			
			ret.setData(svcData.findSpecialUser());
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("查找特殊岗位适配模型失败");
			e("查找特殊岗位适配模型失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.EmployeeUrl.EMP_STANDARD_UPDATE)
	@ResponseBody
	public DataResponse<EmployeeCaution> updateStandardUserModel(@RequestParam List<Integer> team, @RequestParam List<Integer> job) {
		DataResponse<EmployeeCaution> ret = new DataResponse<EmployeeCaution>();
		try {
			validateTimeout();
			ret.setDesc("team: " + team.toString() + ", job: " + job);
			svcData.updateStandardUser(team, job);
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("更新通用岗位适配模型失败");
			e("更新通用岗位适配模型失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.EmployeeUrl.EMP_STANDARD_FIND)
	@ResponseBody
	public DataResponse<EmployeeCaution> findStandardUserModel() {
		DataResponse<EmployeeCaution> ret = new DataResponse<EmployeeCaution>();
		try {
			validateTimeout();
			
			ret.setData(svcData.findStandardUser());
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("查找通用岗位适配模型失败");
			e("查找通用岗位适配模型失败", ex);
		}

		return ret;
	}

	/**
	 * 专业化人岗适配预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:35:04
	 * @return
	 */
	@RequestMapping(value = Paths.EmployeeUrl.EMP_PROFECIAL11, method = { RequestMethod.GET, RequestMethod.POST })
	public String professionalPage11(Model model) {
		String ret= "/mind/emp-professional-1-1";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.categroies());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.USER_PROFESSION);
		}catch(MindException me) {
			ret=pageError(model, me.getMessage());
			e(me.getMessage(), me);
		}catch(Exception ex) {
			ret = pageError(model, ex.getMessage());
			e("", ex);
		}
		return ret;
	}
	
	@RequestMapping(value = Paths.EmployeeUrl.EMP_PROFECIAL12, method = { RequestMethod.GET, RequestMethod.POST })
	public String professionalPage12(Model model) {
		String ret= "/mind/emp-professional-1-2";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.categroies());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.USER_PROFESSION);
		}catch(MindException me) {
			ret=pageError(model, me.getMessage());
			e(me.getMessage(), me);
		}catch(Exception ex) {
			ret = pageError(model, ex.getMessage());
			e("", ex);
		}
		return ret;
	}
	
	@RequestMapping(value = Paths.EmployeeUrl.EMP_PROFECIAL21, method = { RequestMethod.GET, RequestMethod.POST })
	public String professionalPage21(Model model) {
		String ret= "/mind/emp-professional-2-1";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.categroies());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.USER_PROFESSION);
		}catch(MindException me) {
			ret=pageError(model, me.getMessage());
			e(me.getMessage(), me);
		}catch(Exception ex) {
			ret = pageError(model, ex.getMessage());
			e("", ex);
		}
		return ret;
	}
	
	@RequestMapping(value = Paths.EmployeeUrl.EMP_PROFECIAL22, method = { RequestMethod.GET, RequestMethod.POST })
	public String professionalPage22(Model model) {
		String ret= "/mind/emp-professional-2-2";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.categroies());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.USER_PROFESSION);
		}catch(MindException me) {
			ret=pageError(model, me.getMessage());
			e(me.getMessage(), me);
		}catch(Exception ex) {
			ret = pageError(model, ex.getMessage());
			e("", ex);
		}
		return ret;
	}

	@PostMapping(value = Paths.EmployeeUrl.EMP_PROFECIAL_SUM)
	@ResponseBody
	public DataResponse<UserView> professionalQuery(
			@RequestParam(value="spec", defaultValue="false")boolean isSpecial,
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<UserView> ret = new DataResponse<UserView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listEmployee(isSpecial, teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出通用人岗适配分析数据失败");
			e("列出通用人岗适配分析数据失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.EmployeeUrl.EMP_SPECIAL_SUM)
	@ResponseBody
	public DataResponse<SpecialView> specialQuery(
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<SpecialView> ret = new DataResponse<SpecialView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listSpecialUser(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出特殊岗位分析数据失败");
			e("列出特殊岗位分析数据失败", ex);
		}

		return ret;
	}


	@PostMapping(value = Paths.EmployeeUrl.EMP_PIVOTAL_SUM)
	@ResponseBody
	public DataResponse<JobView> pivotalQuery(
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<JobView> ret = new DataResponse<JobView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listJobUser(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出轮岗混岗分析数据失败");
			e("列出轮岗混岗分析数据失败", ex);
		}

		return ret;
	}
	
	/**
	 * 特殊岗位持证情况预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:35:10
	 * @return
	 */
	@RequestMapping(value = Paths.EmployeeUrl.EMP_SPECIAL, method = { RequestMethod.GET, RequestMethod.POST })
	public String specialPage(Model model) {
		String ret= "/mind/emp-special";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.categroies());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.USER_SPECIAL);
		}catch(MindException me) {
			ret=pageError(model, me.getMessage());
			e(me.getMessage(), me);
		}catch(Exception ex) {
			ret = pageError(model, ex.getMessage());
			e("", ex);
		}
		return ret;
	}
	
	/**
	 * 关键岗位轮岗混岗预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:35:16
	 * @return
	 */
	@RequestMapping(value = Paths.EmployeeUrl.EMP_PIVOTAL11, method = { RequestMethod.GET, RequestMethod.POST })
	public String pivotalPage11(Model model) {
		String ret= "/mind/emp-pivotal-1-1";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.categroies());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.USER_PIVOTAL);
		}catch(MindException me) {
			ret=pageError(model, me.getMessage());
			e(me.getMessage(), me);
		}catch(Exception ex) {
			ret = pageError(model, ex.getMessage());
			e("", ex);
		}
		return ret;
	} 

	@RequestMapping(value = Paths.EmployeeUrl.EMP_PIVOTAL12, method = { RequestMethod.GET, RequestMethod.POST })
	public String pivotalPage12(Model model) {
		String ret= "/mind/emp-pivotal-1-2";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.categroies());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.USER_PIVOTAL);
		}catch(MindException me) {
			ret=pageError(model, me.getMessage());
			e(me.getMessage(), me);
		}catch(Exception ex) {
			ret = pageError(model, ex.getMessage());
			e("", ex);
		}
		return ret;
	} 
}
